package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

// 华为机试题 分配内存
// 第一个元素内存快大小, 第二个元素多少块
// 输入需要分配的内存大小
// 输出:true,true,true,false,false

// 64:2,128:1,32:4,1:128
// 50,36,64,128,127

// 测试用例通过率 98%
func main() {

	scan := bufio.NewScanner(os.Stdin)
	scan.Split(bufio.ScanLines)

	memory := make([]int, 0)
	countMap := make(map[int]int)
	reqSlice := make([]int, 0)

	var l1, l2 string
	for i := 0; i < 2; i++ {
		if scan.Scan() {
			if i == 0 {
				l1 = scan.Text()
			} else {
				l2 = scan.Text()
			}
		}
	}

	t := strings.Split(l1, ",")
	for _, v := range t {
		typeAndCount := strings.Split(v, ":")
		size, _ := strconv.Atoi(typeAndCount[0])
		count, _ := strconv.Atoi(typeAndCount[1])
		memory = append(memory, size)
		countMap[size] = count
	}
	sort.Ints(memory)

	rs := strings.Split(l2, ",")
	for _, v := range rs {
		r, _ := strconv.Atoi(v)
		reqSlice = append(reqSlice, r)
	}

	res := make([]bool, len(reqSlice))
	for j, req := range reqSlice {
		if req < 0 || req > 1024 {
			res[j] = false
			continue
		}
		for _, v := range memory {
			if req <= v && countMap[v] > 0 {
				res[j] = true
				countMap[v] = countMap[v] - 1
				break
			} else {
				continue
			}
		}

	}

	length := len(res)
	for i := 0; i < length; i++ {
		fmt.Print(res[i])
		if i < length-1 {
			fmt.Print(",")
		}
	}

}
